Dependency Injection Lifetimes

1 min read
Rapid overview

Dependency Injection Lifetimes (Frontend)

Angular uses hierarchical injectors to control service lifetimes.


Common scopes

  • Root providers: Singleton for the entire app.
  • Module/feature providers: Singleton per feature boundary.
  • Component providers: New instance per component instance.

Testing tips

  • Provide mocks in TestBed for unit tests.
  • Use component-level providers to isolate state.

Interview prompt

  • When would you scope a service at the component level?